def Initialise():
    global NumberOfJobs
    NumberOfJobs=0
    for l in range(99): # M:元素个数不对吧 -1
        Jobs[l][0]=-1
        Jobs[l][1] = -1

def AddJob(JobNumber,Priority):
    global NumberOfJobs
    if NumberOfJobs<99 and NumberOfJobs>=0:
        Jobs[NumberOfJobs][0]=JobNumber
        Jobs[NumberOfJobs][1]=Priority
        print('Added')
        NumberOfJobs+=1
    else:
        print('Not Added')

def InsertionSort():
    #M:写的这么别扭吗 -1
    i=0
    place = 0
    while i != NumberOfJobs:
        if Jobs[place][1]>Jobs[place+1][1]:
            Jobs[place][1],Jobs[place+1][1]=Jobs[place+1][1],Jobs[place][1]
            Jobs[place][0], Jobs[place + 1][0] = Jobs[place + 1][0], Jobs[place][0]
            while Jobs[place-1][1]>Jobs[place][1] and place!=-1:
                Jobs[place-1][1], Jobs[place][1] = Jobs[place][1], Jobs[place-1][1]
                Jobs[place-1][0], Jobs[place][0] = Jobs[place][0], Jobs[place-1][0]
                place = place - 1
        place+=1
        i+=1

def PrintArray():
    global NumberOfJobs
    for i in range(NumberOfJobs):
        print(Jobs[i][0],'priority',Jobs[i][1])


if __name__ == '__main__':
    Jobs=[[None for i in range(2)] for k in range(99)] # M:元素个数不对吧 -1
    global NumberOfJobs

    Initialise()
    AddJob(12,10)
    AddJob(526,9)
    AddJob(33,8)
    AddJob(12,9)
    AddJob(78,1)



    InsertionSort()
    PrintArray()

